package com.ninong.ker.admin.rest;

import com.ninong.ker.admin.service.dto.DicDetailDTO;
import com.ninong.ker.common.tools.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ninong.ker.admin.domain.DicDetail;
import com.ninong.ker.admin.sevice.DicDetailService;
import com.ninong.ker.common.annotation.log.Log;
import com.ninong.ker.common.annotation.perm.CmdAdmin;
import com.ninong.ker.common.response.CmdResponse;

/**
 * 系统字典明细
 * 
 * @author cmd
 *
 */
@RestController
@RequestMapping("/cmd/v1/detail")
public class DicDetailResources {

	@Autowired
	private DicDetailService detailService;

	@Log("字典明细列表")
	@CmdAdmin({ "admin", "dic:detail" })
	@PostMapping
	public ResponseEntity<CmdResponse> list(@RequestBody DicDetailDTO entity) {
		CmdResponse response = new CmdResponse();
		response.setData(detailService.listPage(entity));
		return ResponseEntity.ok(response);
	}

	@Log("字典明细删除")
	@CmdAdmin({ "admin", "dic:detail" })
	@DeleteMapping
	public ResponseEntity<CmdResponse> delete(@RequestBody String[] ids) {
		CmdResponse response = new CmdResponse();
		detailService.delete(ids);
		String mess = PropertyUtil.getProperty("DELETE_SUCCESS");
		response.setMessage(mess);
		return ResponseEntity.ok(response);
	}

	@Log("字典明细新增或编辑")
	@CmdAdmin({ "admin", "dic:detail" })
	@PutMapping
	public ResponseEntity<CmdResponse> create(@RequestBody DicDetail entity) {
		detailService.create(entity);
		return ResponseEntity.ok(new CmdResponse());
	}

	@Log("字典明细详情")
	@CmdAdmin({ "admin", "dic:detail" })
	@GetMapping(value = "/{id}")
	public ResponseEntity<CmdResponse> get(@PathVariable String id) {
		CmdResponse response = new CmdResponse();
		response.setData(detailService.get(id));
		return ResponseEntity.ok(response);
	}

}
